package com.pur.zsms.weixinpay.weixinPayCaddemo;

import java.net.ConnectException;
import java.util.Map;
import java.util.TreeMap;

import com.pur.zsms.weixinpay.weixinPayCaddemo.dao.QueryDao;
import com.pur.zsms.weixinpay.weixinPayCaddemo.utils.ClientCustomSSL;
import com.pur.zsms.weixinpay.weixinPayCaddemo.utils.HttpUtil;
import com.pur.zsms.weixinpay.weixinPayCaddemo.utils.XMLUtil;

public class wechatcancel {

public static void ordercancel(QueryDao qd) throws Exception {
		
		String appid = qd.getAppid()==null?"":qd.getAppid();
		String mch_id = qd.getMch_id()==null?"":qd.getMch_id();
		String out_trade_no = qd.getOut_trade_no()==null?"":qd.getOut_trade_no();//商户系统内部的订单号，微信订单号、商户订单号二选一必传
		String sub_mch_id = qd.getSub_mch_id()==null?"":qd.getSub_mch_id();
		
		String currTime = Method.getCurrTime(); 
		String time_start = currTime.substring(8, currTime.length());
		String strRandom = Method.buildRandom(4) + "";
		String nonce_str = time_start + strRandom; //随机数生成算法
		
		String sign = "";//签名
		
		//String QUERY_URL = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
		
		String key = "645yh45y45y45y45y45y45y45y45y5445y";
		
		Map<Object, String> map = new TreeMap<Object, String>();
		map.put("appid", appid);
		map.put("mch_id", mch_id);
		map.put("out_trade_no", out_trade_no);
		map.put("sub_mch_id", sub_mch_id);
		map.put("nonce_str", nonce_str);
		sign = Method.createSign("UTF-8", map,key);
		map.put("sign", sign);
		
		String requestXML = Method.getRequestXml(map);

		ClientCustomSSL clientCustomSSL = new ClientCustomSSL();
		clientCustomSSL.clientcustomSSL(requestXML);
		
		System.out.println("Cancel resXml::::");
		
		
	}
}
